package conf

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"metabank/constants"
	"os"
)

type Config struct {
	SliceInfoOptions []SliceInfoOptions `json:"sliceInfo,omitempty" yaml:"sliceInfo,omitempty" mapstructure:"sliceInfo"`
	IdcName          string             `json:"idcName,omitempty"`
	Namespace        string             `json:"namespace,omitempty"`
}

type SliceInfoOptions struct {
	Number string `json:"number" yaml:"number"`
	Idc    string `json:"idc" yaml:"idc"`
}

func NewAddressOptions() []SliceInfoOptions {

	c1 := &[]SliceInfoOptions{}
	content, err := ioutil.ReadFile(constants.DefaultConfigurationPath + "/" + constants.DefaultConfigurationName)
	if err != nil {
		fmt.Println(err)
	}
	err = yaml.Unmarshal(content, c1)
	if err != nil {
		fmt.Println(err)
	}

	return *c1

}

func New() *Config {
	return &Config{
		SliceInfoOptions: NewAddressOptions(),
		IdcName:          os.Getenv("METABANK_IDC_NAME"),
		Namespace:        os.Getenv("NAMESPACE"),
	}
}
